// 简单图片轮播 
/*
/** 未完善
/** by ljh
*/
(function($){
	$.fn.SlideImg = function(options){
		var $self = $.extend(
			{
				ImgSrc: null,
				alink: null,
				Show: 1,
				ItemBg: null,
				ItemNowBg: null,
				leftright: false,
				SetTime: 3000,
				during: 400
			},options);
		var container = $(this);
		
		return this.each(function(){
			var width = container.width();
			var height = container.height();
			
			var ul = $("<ul>");
			var li = "";
			var a = $("<a>");
			var ItemParent = $("<div>");
			var Item = "";
			var left = $("<a>");
			var right = $("<a>");
			var $SetTime;
			var nums = $self.ImgSrc.length;
			
			if($self.ImgSrc == null){
				return false;
			}else{
				for(var i=0; i<nums; i++){
					li += "<li><a href=\""+$self.alink[i]+"\"><img src=\""+$self.ImgSrc[i]+"\" width=\""+width+"\" height=\""+height+"\" /></a></li>";
					Item += "<span></span>";
				}
				
				ul.width(width*nums);
				ul.height(height);
				ul.append(li);
				ItemParent.append(Item);
				container.append(ul);
				container.append(ItemParent);	/*添加组件*/
			}
			switch($self.show){
				case 1: Slide();
			}
			
			/*Css Style*/
			container.css({
				"position": "relative",
				"overflow": "hidden"
			});
			ul.css({
				"position": "absolute",
				"top": 0,
				"left": 0
			});
			ul.find("li").css({
				"float": "left"
			});
			ul.find("img").css({
				"vertical-align": "bottom"
			});
			ItemParent.css({
				"position": "absolute",
				"bottom": "20px",
				"right": "20px",
				"z-index": 3,
				"text-align": "right"
			});
			ItemParent.find("span").css({
				"display": "inline-block",
				"width": "10px",
				"height": "10px",
				"margin-left": "10px",
				"background": "url('"+$self.ItemBg+"')",
				"cursor": "pointer"
			});
			ItemParent.find("span").eq(0).css("background","url('"+$self.ItemNowBg+"')");
			var index=0;
			$SetTime = setInterval(function(){
				index++;
				if(index>=nums) index = 0;	
				SetTime(index)
			}, $self.SetTime);
			function SetTime(index){	/*定时*/
				ItemParent.find("span").eq(index).css("background","url('"+$self.ItemNowBg+"')").siblings().css("background","url('"+$self.ItemBg+"')");
				ul.animate({"left":-index*width+"px"}, $self.during);
			}
			function Slide(){	/*滑动*/
				ItemParent.find("span").each(function(i, o){
					$(this).click(function(){
						clearInterval($SetTime);
						SetTime(i);
						index = i;
						$SetTime = setInterval(function(){
							index++;
							if(index>=nums) index = 0;	
							SetTime(index)
						}, $self.SetTime);
					});
				});
			}
		})
	}
})(jQuery)